package com.ruitu.mall_98_2.order;

import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.beanu.arad.base.my_base.MyBaseActivity;
import com.beanu.arad.base.my_base.base_list.ListBaseAdapter;
import com.beanu.arad.widget.progressactivity.ProgressLayout;
import com.ruitu.mall_98_2.R;
import com.ruitu.router_module.A_Rutils;
import com.ruitu.router_module.AppHolder;
import com.ruitu.router_module.bean.DataAdapter;
import com.ruitu.router_module.bean.order.ConfirOrder;
import com.ruitu.router_module.bean.order.SmallOrder;
import com.ruitu.router_module.bean.product.ProHome;
import com.ruitu.router_module.bean.product.Product;

import java.util.ArrayList;
import java.util.List;

public class PayResultActivity extends MyBaseActivity {
    private TextView tv_recipients;
    private TextView tv_recipients_tel;
    private TextView tv_shipping_address;
    private TextView tv_pay_result_total;
    private TextView tv_check_order;
    private RecyclerView recyclerView;
    private String payMoney;
    private String orderId;
    private DataAdapter adapter;

    private ConfirOrder confirOrders;
    private List<Integer> skipId = new ArrayList<>();

    @Override
    protected int getLayoutRes() {
        return R.layout.activity_pay_result;
    }

    @Override
    protected ProgressLayout findProgressLayout() {
        return null;
    }

    @Override
    protected void initViews() {
        super.initViews();
        setHeadTitle("支付成功");
        confirOrders = (ConfirOrder) getIntent().getExtras().getSerializable("confirOrder");
        tv_recipients = findViewById(R.id.tv_recipients);
        tv_recipients_tel = findViewById(R.id.tv_recipients_tel);
        tv_shipping_address = findViewById(R.id.tv_shipping_address);
        tv_pay_result_total = findViewById(R.id.tv_pay_result_total);
        tv_check_order = findViewById(R.id.tv_check_order);
        tv_check_order.setOnClickListener(this);
        recyclerView = findViewById(R.id.recyclerView);

        GridLayoutManager manager = new GridLayoutManager(this, 2) {
            @Override
            public boolean canScrollVertically() {
                return false;
            }
        };
        recyclerView.setLayoutManager(manager);
        adapter = new DataAdapter(this);
        recyclerView.setAdapter(adapter);
        initData();
    }

    private void initData() {
        final List<ProHome> globalProList = AppHolder.instance().getGlobalProList();
        tv_recipients.setText(confirOrders.getConsigneeName());
        tv_recipients_tel.setText(confirOrders.getCollectGoodsPhone());
        tv_shipping_address.setText(confirOrders.getOrderProvinceCode() + confirOrders.getOrderCityCode() + confirOrders.getOrderCountyCode() + confirOrders.getCollectGoodsAddress());
        tv_pay_result_total.setText("￥" + confirOrders.getNeedPay());
        adapter.setDataList(globalProList);

        adapter.setOnItemClickListener(new ListBaseAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View itemView, int position) {
                Product product = new Product();
                product.setGoodId(globalProList.get(position).getGoodsId());
                Bundle bundle = new Bundle();
                bundle.putSerializable("product", product);
                try {
                    A_Rutils.startActivity(PayResultActivity.this, "com.ruitu.mall_98_1.product.activity.ProductDetailActivity", bundle);
                } catch (ClassNotFoundException e) {
                    e.printStackTrace();
                }
            }
        });
    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        if (tv_check_order == v) {
            SmallOrder smallOrder = new SmallOrder();
            smallOrder.setId(confirOrders.getId());
        }
    }

}
